home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frm10_4_5
- Caption = "Browser Market Share"
- ClientHeight = 5748
- ClientLeft = 1908
- ClientTop = 1740
- ClientWidth = 8292
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 7.8
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- LinkTopic = "Form1"
- PaletteMode = 1 'UseZOrder
- ScaleHeight = 5748
- ScaleWidth = 8292
- Begin VB.PictureBox picShare
- Height = 4935
- Left = 600
- ScaleHeight = 4884
- ScaleWidth = 7044
- TabIndex = 1
- Top = 720
- Width = 7095
- End
- Begin VB.CommandButton cmdDraw
- Caption = "Draw Market Share Pie Chart"
- Height = 495
- Left = 2640
- TabIndex = 0
- Top = 120
- Width = 2775
- End
- Attribute VB_Name = "frm10_4_5"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Private Sub cmdDraw_Click()
- Dim numItems As Integer, radius As Single
- 'Draw pie chart of Browser Market Share
- numItems = 3
- ReDim category(1 To numItems) As String
- ReDim quantity(1 To numItems) As Single
- Call ReadData(category(), quantity(), numItems)
- Call DrawData(quantity(), numItems, radius)
- Call ShowLegend(category(), numItems, radius)
- Call ShowTitle(radius)
- End Sub
- Private Sub DrawData(quantity() As Single, numItems As Integer, radius As Single)
- Dim circumf As Single, leftEdge As Single, rightEdge As Single
- Dim topEdge As Single, bottomEdge As Single, i As Integer
- Dim startAngle As Single, stopAngle As Single
- 'Draw and fill each sector of pie chart
- 'All scaling and text positioning done as a percentage of radius
- radius = 1 'actual value used is not important
- 'Make picture 4 radii wide to provide plenty of space for
- 'circle and legends. Place origin 1.25 radii from left edge;
- 'space of 1.75 radii will remain on right for legends.
- leftEdge = -1.25 * radius
- rightEdge = 2.75 * radius
- 'Force vertical scale to match horizontal scale;
- 'center origin vertically
- topEdge = 2 * radius * (picShare.Height / picShare.Width)
- bottomEdge = -topEdge
- picShare.Cls
- picShare.Scale (leftEdge, topEdge)-(rightEdge, bottomEdge)
- circumf = 2 * 3.14159
- ReDim cumPercent(0 To numItems) As Single
- cumPercent(0) = 0.0000001 'a value of "zero" that can be made negative
- For i = 1 To numItems
- cumPercent(i) = cumPercent(i - 1) + quantity(i)
- startAngle = cumPercent(i - 1) * circumf
- stopAngle = cumPercent(i) * circumf
- picShare.FillStyle = (8 - i) 'use fill patterns 7, 6, and 5
- picShare.Circle (0, 0), radius, , -startAngle, -stopAngle
- Next i
- End Sub
- Private Sub Locate(x As Single, y As Single)
- picShare.CurrentX = x
- picShare.CurrentY = y
- End Sub
- Private Sub ReadData(category() As String, quantity() As Single, numItems As Integer)
- Dim i As Integer
- 'Load categories and percentages of market share
- 'Assume the data has been placed in the file BROWSERS.DAT
- '(First line in file is "Internet Explorer", .44)
- Open App.Path & "\BROWSERS.TXT" For Input As #1
- For i = 1 To numItems
- Input #1, category(i), quantity(i)
- Next i
- Close #1
- End Sub
- Private Sub ShowLegend(category() As String, numItems As Integer, radius As Single)
- Dim lblHght As Single, legendSize As Single
- Dim i As Integer, vertPos As Single
- 'Place legend centered to right of pie chart
- 'Make separation between items equal to one line of text
- '"Text lines" needed for legends is thus (2*numItems-1)
- lblHght = picShare.TextHeight(" ")
- legendSize = lblHght * (2 * numItems - 1)
- For i = 1 To numItems
- picShare.FillStyle = 8 - i
- vertPos = (legendSize / 2) - (3 - i) * (2 * lblHght)
- picShare.Line (1.1 * radius, vertPos)-(1.4 * radius, vertPos + lblHght), , B
- Call Locate(1.5 * radius, vertPos)
- picShare.Print category(i)
- Next i
- End Sub
- Private Sub ShowTitle(radius As Single)
- Dim lbl As String, lblWid As Single
- 'Display title right below circle
- lbl = "Browser Market Share, July 1998"
- lblWid = picShare.TextWidth(lbl)
- Call Locate(-lblWid / 2, -(radius + 0.05))
- picShare.Print lbl
- End Sub
-